<?
#include "DB/DataBase.class.php";
#include "GUI/ComboBox.class.php";

class GridSearcher{

	public static function SearchString($sql, $column, $value, $searchQryCondition = " WHERE "){
	
		$has_where = strrpos($sql, "WHERE");
		$has_order_clause = strpos($sql, "ORDER");
		
		if ($has_where) 			$qry_condiotion = " AND ";			
		else						$qry_condiotion = " WHERE ";
		
#		if($has_order_clause)		
			
		
		
		
		if($column != "" && $value != "")
			return $sql." ".$qry_condiotion." $column LIKE '%" . $value . "%' ";			
		else
			return $sql;
	}
	
	public static function Render($sql){
		
		$names = DataBase::FieldsName($sql);
		$cmb = new Combo();
		foreach($names as $value)
			$cmb->AddItem($value);
			
		echo "<div>\n";
		echo "<form name=\"form1\" method=\"post\" action=\"\">";
		$cmb->Render("grid_search_field");
		echo "<input type=\"text\" name=\"grid_search_value\">";
		echo "<input type=\"submit\" name=\"Submit\" value=\"Buscar\">";
		echo "</form>\n";
		echo "</div>\n";
	}
}
#$sql = "SELECT * FROM socios";
#echo GridSearcher::SearchString($sql, $grid_search_field, $grid_search_value);
#GridSearcher::Render();
#print_r($_REQUEST);
?>
